// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file is part of CodingEditor.
// Note:	This project is derived from Peter Project
//			(hosted on sourceforge and codeplex)
//
// Copyright (c) 2008-2009, CE Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


namespace CE.Classes
{
	using System;
	using System.Collections;

	using CE.API;

	public class cPluginCollection : CollectionBase
	{
		#region Constructors

		public cPluginCollection()
		{
		}

		#endregion Constructors

		#region Indexers

		/// <summary>
		/// Gets a ICodingEditorPlugin at the requested Index...
		/// </summary>
		/// <param name="index">Index of ICodingEditorPlugin...</param>
		/// <returns>ICodingEditorPlugin at requested Index...</returns>
		public ICEPlugin this[int index]
		{
			get{
				// Make sure it is a valid index...
				if (index < 0 || index >= this.Count) {
					return null;
				}

				// Return the tabber page...
				return this.List[index] as ICEPlugin;
			}
		}

		#endregion Indexers

		#region Methods

		/// <summary>
		/// Adds a ICodingEditorPlugin to the collection...
		/// </summary>
		/// <param name="page">ICodingEditorPlugin to add...</param>
		/// <returns>Added ICodingEditorPlugin's index</returns>
		public int Add(ICEPlugin plugin)
		{
			// Make sure the plugin is not null...
			if (plugin == null) {
				throw new ArgumentNullException("ICodingEditorPlugin", "ICodingEditorPlugin is null!");
			}

			return this.List.Add(plugin);
		}

		/// <summary>
		/// Removes all ICodingEditorPlugins from the collection...
		/// </summary>
		public new void Clear()
		{
			if (this.Count == 0) {
				// Nothing to do, return...
				return;
			}

			// Clear the list...
			base.Clear();

			// Rest the Capacity...
			this.InnerList.Capacity = 0;
		}

		/// <summary>
		/// Gets the index of a specified ICodingEditorPlugin...
		/// </summary>
		/// <param name="page">ICodingEditorPlugin to get index for...</param>
		/// <returns>Index of ICodingEditorPlugin</returns>
		public int IndexOf(ICEPlugin plugin)
		{
			// Look for the ICodingEditorPlugin...
			for (int a = 0; a < this.Count; a++) {
				if (this[a] == plugin) {
					// Found it...
					return a;
				}
			}

			// Not found...
			return -1;
		}

		/// <summary>
		/// Removes a ICodingEditorPlugin from the Collection...
		/// </summary>
		/// <param name="page">ICodingEditorPlugin to remove...</param>
		public void Remove(ICEPlugin plugin)
		{
			// Get the index of the plugin...
			int index = this.IndexOf(plugin);

			// Make sure it is a valid index...
			if (index != -1) {
				// Remove Page...
				this.RemoveAt(index);
			}
		}

		#endregion Methods
	}
}